public class java2024_6_1 {
    public static void main(String[] args) {
        //异常 - 程序的非正常运行

        //异常的体系结构 - Throwable - error + Exception
        try {
            isBig(0);
        } catch (ArithmeticException e) {
            System.out.println("异常已经被捕获了...");
            //最后打印
            e.printStackTrace();
        } catch (NullPointerException e) {
            e.printStackTrace();
        } catch (ArrayIndexOutOfBoundsException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            System.out.println("finally里面的代码总会被执行...");
        }
        System.out.println("这是之后的代码");


    }

    public static void isBig(int number) throws ArithmeticException, NullPointerException, ArrayIndexOutOfBoundsException {
        //异常 - 抛出异常
        if (number == 0) {
            throw new ArithmeticException("数字为0...");
        }
        if (number == 1) {
            throw new NullPointerException();
        }
        if (number == 2) {
            throw new ArrayIndexOutOfBoundsException();
        }
    }
}
